﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using X.Web;
using X.Entity;

namespace X.WebSite.Admin.Page
{
    public partial class Detail : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
            _FileBrowser.BasePath = "../ckfinder/";
            _FileBrowser.SetupCKEditor(ckePageContent);

            if (!IsPostBack)
            {
                string pageKey = string.Empty;

                if (!string.IsNullOrEmpty(Request.QueryString["PageKey"]))
                    pageKey = Request.QueryString["PageKey"];

                if (string.Empty == pageKey)
                    Response.Redirect("List.aspx");

                PageInfo pageInfo = Bll.Page.GetPageInfo(pageKey);

                txtPageDescription.Text = X.Common.StringUtils.HtmlDecode(pageInfo.PageDescription);
                ckePageContent.Text = pageInfo.PageContent;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            PageInfo pageInfo;

            if (!string.IsNullOrEmpty(Request.QueryString["PageKey"]))
            {
                pageInfo = Bll.Page.GetPageInfo(Request.QueryString["PageKey"]);

                pageInfo.PageDescription = X.Common.StringUtils.HtmlEncode(txtPageDescription.Text);
                pageInfo.PageContent = ckePageContent.Text;

                Bll.Page.Update(pageInfo);
            }

            Response.Redirect("List.aspx");
        }
    }
}